package cn.xingzhen.jfield.componet;

import javax.swing.*;
import java.awt.*;

/**
 * @author wenqiang
 * @date 2023/5/6
 * @comment ..
 */
public class XzLabel extends JLabel {


    public XzLabel(String text) {
        super(text);
        Dimension labelSize = new Dimension(XzUIConfigure.DEFAULT_WIDTH_LABEL, XzUIConfigure.DEFAULT_COMPONENT_HEIGHT);
        setPreferredSize(labelSize);
        initDefault();
    }

    public XzLabel(String text, int width) {
        super(text);
        Dimension labelSize = new Dimension(width, XzUIConfigure.DEFAULT_COMPONENT_HEIGHT);
        setPreferredSize(labelSize);

        initDefault();
    }

    private void initDefault() {
        setHorizontalAlignment(JLabel.CENTER);
        if(XzUIConfigure.SHOW_BORDER) {
            setBorder(BorderFactory.createLineBorder(XzUIConfigure.BORDER_COLOR));
        }
    }

    public XzLabel setWidth(int width) {
        Dimension labelSize = new Dimension(width, XzUIConfigure.DEFAULT_COMPONENT_HEIGHT);
        setPreferredSize(labelSize);
        return this;
    }

    public XzLabel setAlignment(int alignment) {
        setHorizontalAlignment(alignment);
        return this;
    }
}
